﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Drawing.Imaging;

namespace ScreenShot
{
    public partial class Form1 : Form
    {
        private pictureManager.pictureManager picManager = new pictureManager.pictureManager();
        private int previousWidth, previousHeight;
      
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            pictureBox1.Image = picManager.takeScreenshot();
            this.Visible = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = null;
        }

        private void Form1_ResizeBegin(object sender, EventArgs e)
        {
            previousHeight = this.Height;
            previousWidth = this.Width;
        }

        private void Form1_ResizeEnd(object sender, EventArgs e)
        {

            resizePictureBox();
          
        }

        private void resizePictureBox()
        {
            this.pictureBox1.Height += this.Height - previousHeight;
            this.pictureBox1.Width += this.Width - previousWidth;
            previousHeight = this.Height;
            previousWidth = this.Width;
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
                     
                resizePictureBox();
           
        }

        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            resizePictureBox();
        }

        private void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {
                        picManager.WithForm = checkBox1.Checked;
        }

        private void button3_Click(object sender, EventArgs e)
        {
         EncoderParameter encParameter = new EncoderParameter(Encoder.Quality,255);
         EncoderParameters encParameters = new EncoderParameters(1);
         encParameters.Param[0] = encParameter;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title = "Save an Image File";
            saveFileDialog1.ShowDialog();

            
            if (saveFileDialog1.FileName != "")
            {
                   System.IO.FileStream fs =
                   (System.IO.FileStream)saveFileDialog1.OpenFile();
                
                switch (saveFileDialog1.FilterIndex)
                {
                    case 1:
                        this.pictureBox1.Image.Save(fs,
                           System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case 2:
                        this.pictureBox1.Image.Save(fs,
                           System.Drawing.Imaging.ImageFormat.Bmp);
                        break;

                    case 3:
                        this.pictureBox1.Image.Save(fs,
                           System.Drawing.Imaging.ImageFormat.Gif);
                        break;
                }

                fs.Close();
            }
        }
       
        

     
    }
}
